package hu.ikti.oamadmin.types.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.jboss.seam.annotations.Name;

@Entity
@Name("serviceprofile")
@Table(name = "SERVICEPROFILE")
@SequenceGenerator(sequenceName = "SERVICEPROFILE_SEQ", name = "SP_SEQ", allocationSize = 1)
public class ServiceProfile implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String name;
	private String description;
	private List<Service> services = new ArrayList<Service>();
	private List<Bundle> bundles = new ArrayList<Bundle>();
	private List<Resource> resources = new ArrayList<Resource>();

	public ServiceProfile() {
	}

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "SP_SEQ")
	public Long getId() {
		return id;
	}

	@Column(name = "SERVICEPROFILE_NAME", nullable = false)
	public String getName() {
		return name;
	}

	@Column(name = "SERVICEPROFILE_DESCRIPTION")
	public String getDescription() {
		return description;
	}

	@ManyToMany
	@JoinTable(name = "SERVICEPROFILE_SERVICE_RT", joinColumns = { @JoinColumn(name = "SERVICEPROFILE_FK") }, inverseJoinColumns = { @JoinColumn(name = "SERVICE_FK") })
	public List<Service> getServices() {
		return services;
	}

	@OneToMany(fetch = FetchType.LAZY)
	@JoinColumn(name = "SERVICEPROFILE_FK")
	public List<Bundle> getBundles() {
		return bundles;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "SERVICEPROFILE_RESOURCE_RT", joinColumns = { @JoinColumn(name = "SERVICEPROFILE_FK", referencedColumnName = "ID") }, inverseJoinColumns = { @JoinColumn(name = "RESOURCE_FK", referencedColumnName = "ID") })
	public List<Resource> getResources() {
		return resources;
	}

	public void setResources(List<Resource> resources) {
		this.resources = resources;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setServices(List<Service> services) {
		this.services = services;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setBundles(List<Bundle> bundles) {
		this.bundles = bundles;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServiceProfile other = (ServiceProfile) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
